package tr.edu.metu.is.mega.client.core;

import com.extjs.gxt.ui.client.widget.LayoutContainer;

/**
 * Singleton screen mediator frame.
 */
public final class ScreenMediator {

    private static ScreenMediator instance = null;

    private LayoutContainer container = null;

    /**
     * Default constructor.
     */
    private ScreenMediator() {
    }

    /**
     * Returns singleton instance of this.
     * 
     * @return singleton instance of this
     */
    public static ScreenMediator getInstance() {
        if (instance == null) {
            instance = new ScreenMediator();
        }
        return instance;
    }

    /**
     * Sets window container.
     * 
     * @param container window container
     */
    public void setContainer(LayoutContainer container) {
        this.container = container;
    }

    /**
     * Displays a window.
     * 
     * @param window window to display
     */
    public void display(MainWindow window) {
        if (container == null) {
            throw new IllegalStateException("Screen mediator is not initialized");
        }
        container.removeAll();
        container.add(window);
        container.layout(true);
    }

}
